package com.ahdy.service.impl;

import com.ahdy.entity.ShareTarget;
import com.ahdy.mapper.ShareTargetMapper;
import com.ahdy.service.ShareTargetService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 共享对象服务实现类
 */
@Service
public class ShareTargetServiceImpl extends ServiceImpl<ShareTargetMapper, ShareTarget> implements ShareTargetService {
    
    @Autowired
    private ShareTargetMapper shareTargetMapper;
    
    @Override
    public List<ShareTarget> getShareTargetsByUserIdAndType(Integer userId, String type) {
        return shareTargetMapper.selectByUserIdAndType(userId, type);
    }
    
    @Override
    public List<ShareTarget> getShareTargetsByUserId(Integer userId) {
        LambdaQueryWrapper<ShareTarget> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ShareTarget::getUserId, userId);
        return list(wrapper);
    }
    
    @Override
    public boolean addShareTarget(ShareTarget shareTarget) {
        // 设置创建和更新时间
        shareTarget.setCreateTime(LocalDateTime.now());
        shareTarget.setUpdateTime(LocalDateTime.now());
        return save(shareTarget);
    }
    
    @Override
    public boolean updateShareTarget(ShareTarget shareTarget) {
        // 设置更新时间
        shareTarget.setUpdateTime(LocalDateTime.now());
        return updateById(shareTarget);
    }
    
    @Override
    public boolean deleteShareTarget(Integer id) {
        return removeById(id);
    }
} 